Function code generation
Description
An example
Test programs
Description
Modify the parser to generate assembly like code for the whole program.
The specific requirements are:
-
As in previous projects, your parser should ignore (but copy) "meta-statements"
at the beginningof the program.
-
The output program uses the same grammar as the input program as in the
previous
assignment except that this project does not allow any functions
other main. The program have one and only one data array of a constant
size.
-
As with the previous assignment, the output program should be compilable
by CC compiler and have the same behavior as the input program.
-
You may use a jump table to implement parameterized gotos. Or you
may use a while loop, as in the this example
program.
Implementation of Polymorphism (for 454 students)
-
In this project, you can assume that the input program has only functions
(with parameters) and read/write statements. In other words, you
don't need to implement type propagation.
-
Each integer is of either decimal (int10) or binary (int2). But they
can all be referenced and passed around by type int. Your compiler
should always use the right input/output methods for each integer at runtime.
For binary numbers, use "readint2" and "writeint2". For decimal numbers,
use "readint10" and "writeint10".
An example
original program
program after intra-function
code generation
program after function
code generation
Test programs
Three example programs and their sample generated
programs are here. Scroll down to see the content of README.